<?php

namespace App\Http\Controllers\Home;

use App\Models\Week;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Banner;
use App\Models\Teache;
use App\Models\Good;
use App\Models\Expert;
use App\Models\Leav;
use App\Models\Yun;
use App\Models\Busines;
class IndexController extends Controller
{
    public function index(Banner $banner){
        $data = $banner->get();
        $teach = new Teache();
        $teach_data = $teach->orderby('id','asc')->get();
        $good = new Good();
        $good_data = $good->where('recomm','yes')->limit(6)->get();
        $bussines = new Busines();
        $bussines_data = $bussines->limit(6)->orderby('id','asc')->get();
        return view('home/index/index',['data'=>$data,'tea'=>$teach_data,'good'=>$good_data,'bussines'=>$bussines_data]);
    }
    //公司页面
    public function contact(){
        return view('home/index/contact');
    }
    //team页面
    public function team(){
        $teach = new Teache();
        $data = $teach->orderby('id','asc')->get();
        return view('home/index/team',['data'=>$data]);
    }
    //详情页面
    public function team_details($id){
            $teach = new Teache();
            $data= $teach->where('id',$id)->get();
            return view('home/index/team_details',['data'=>$data]);
    }
    //留言接受
    public function leaving(Request $request){
       $data = $request->except('_token');
       $leaving = new Leav();
       $result = $leaving->create($data);
       return json_encode(['static'=>'yes']);
    }
    //本月运程
    public function month_lucky(Yun $yun){
        $date = date('Y-m');
        $data = $yun->where('date',$date)->get();
        return view('home/index/month_lucky',['data'=>$data]);
    }
    //关于我们
    public function about(){
        return view('home/index/about');
    }
    //公司新闻
    public function news(Yun $yun){
        $data = $yun->get();
        return view('home/index/news',['data'=>$data]);
    }
    //公司新闻
    public function news_details($id){
        $yun = new Yun();
        $data = $yun->where('id',$id)->get();
        return view('home/index/news_details',['data' => $data]);
    }
    //公司历程
    public function summary(){
        return view('home/index/summary');
    }
    //每周吉凶
    public function week(Week $week){
        $week_date = date('Y').'-W'.date('W');
        $data = $week->where('date',$week_date)->get();
        return view('home/index/week',['data'=>$data]);
    }
}